﻿using System;
using System.Collections.Generic;
using System.IO;
using Microsoft.Xna.Framework;
using Terraria.Graphics.Effects;
using Terraria.ID;
using Terraria.Localization;
using Terraria.World.Generation;

namespace Terraria.GameContent.Events
{
	// Token: 0x02000440 RID: 1088
	public class DD2Event
	{
		// Token: 0x1700029E RID: 670
		// (get) Token: 0x0600255A RID: 9562 RVA: 0x0001A49D File Offset: 0x0001869D
		public static bool ReadyToFindBartender
		{
			get
			{
				return NPC.downedBoss2;
			}
		}

		// Token: 0x1700029F RID: 671
		// (get) Token: 0x0600255B RID: 9563 RVA: 0x0001A4A4 File Offset: 0x000186A4
		public static bool DownedInvasionAnyDifficulty
		{
			get
			{
				return DD2Event.DownedInvasionT1 || DD2Event.DownedInvasionT2 || DD2Event.DownedInvasionT3;
			}
		}

		// Token: 0x170002A0 RID: 672
		// (get) Token: 0x0600255C RID: 9564 RVA: 0x0001A4BB File Offset: 0x000186BB
		// (set) Token: 0x0600255D RID: 9565 RVA: 0x0001A4C2 File Offset: 0x000186C2
		public static int TimeLeftBetweenWaves
		{
			get
			{
				return DD2Event._timeLeftUntilSpawningBegins;
			}
			set
			{
				DD2Event._timeLeftUntilSpawningBegins = value;
			}
		}

		// Token: 0x170002A1 RID: 673
		// (get) Token: 0x0600255E RID: 9566 RVA: 0x0001A4CA File Offset: 0x000186CA
		public static bool EnemySpawningIsOnHold
		{
			get
			{
				return DD2Event._timeLeftUntilSpawningBegins != 0;
			}
		}

		// Token: 0x170002A2 RID: 674
		// (get) Token: 0x0600255F RID: 9567 RVA: 0x00485568 File Offset: 0x00483768
		public static bool EnemiesShouldChasePlayers
		{
			get
			{
				bool ongoing = DD2Event.Ongoing;
				return true;
			}
		}

		// Token: 0x170002A3 RID: 675
		// (get) Token: 0x06002560 RID: 9568 RVA: 0x0001A4D4 File Offset: 0x000186D4
		public static bool ReadyForTier2
		{
			get
			{
				return Main.hardMode && NPC.downedMechBossAny;
			}
		}

		// Token: 0x170002A4 RID: 676
		// (get) Token: 0x06002561 RID: 9569 RVA: 0x0001A4E4 File Offset: 0x000186E4
		public static bool ReadyForTier3
		{
			get
			{
				return Main.hardMode && NPC.downedGolemBoss;
			}
		}

		// Token: 0x06002562 RID: 9570 RVA: 0x0001A4F4 File Offset: 0x000186F4
		public static void Save(BinaryWriter writer)
		{
			writer.Write(DD2Event.DownedInvasionT1);
			writer.Write(DD2Event.DownedInvasionT2);
			writer.Write(DD2Event.DownedInvasionT3);
		}

		// Token: 0x06002563 RID: 9571 RVA: 0x0048557C File Offset: 0x0048377C
		public static void Load(BinaryReader reader, int gameVersionNumber)
		{
			if (gameVersionNumber < 178)
			{
				NPC.savedBartender = false;
				DD2Event.ResetProgressEntirely();
				return;
			}
			NPC.savedBartender = reader.ReadBoolean();
			DD2Event.DownedInvasionT1 = reader.ReadBoolean();
			DD2Event.DownedInvasionT2 = reader.ReadBoolean();
			DD2Event.DownedInvasionT3 = reader.ReadBoolean();
		}

		// Token: 0x06002564 RID: 9572 RVA: 0x0001A517 File Offset: 0x00018717
		public static void ResetProgressEntirely()
		{
			DD2Event.DownedInvasionT1 = (DD2Event.DownedInvasionT2 = (DD2Event.DownedInvasionT3 = false));
			DD2Event.Ongoing = false;
			DD2Event.ArenaHitbox = default(Rectangle);
			DD2Event._arenaHitboxingCooldown = 0;
			DD2Event._timeLeftUntilSpawningBegins = 0;
		}

		// Token: 0x06002565 RID: 9573 RVA: 0x004855CC File Offset: 0x004837CC
		public static void ReportEventProgress()
		{
			int progressWave;
			int progressMax;
			int progress;
			DD2Event.GetInvasionStatus(out progressWave, out progressMax, out progress, false);
			Main.ReportInvasionProgress(progress, progressMax, 3, progressWave);
		}

		// Token: 0x06002566 RID: 9574 RVA: 0x004855F0 File Offset: 0x004837F0
		public static void SyncInvasionProgress(int toWho)
		{
			int num;
			int num2;
			int number;
			DD2Event.GetInvasionStatus(out num, out num2, out number, false);
			NetMessage.SendData(78, toWho, -1, null, number, (float)num2, 3f, (float)num, 0, 0, 0);
		}

		// Token: 0x06002567 RID: 9575 RVA: 0x00006B58 File Offset: 0x00004D58
		public static void SpawnNPC(ref int newNPC)
		{
		}

		// Token: 0x06002568 RID: 9576 RVA: 0x00485620 File Offset: 0x00483820
		public static void UpdateTime()
		{
			if (!DD2Event.Ongoing && !Main.dedServ)
			{
				Filters.Scene.Deactivate("CrystalDestructionVortex", new object[0]);
				Filters.Scene.Deactivate("CrystalDestructionColor", new object[0]);
				Filters.Scene.Deactivate("CrystalWin", new object[0]);
				return;
			}
			if (Main.netMode != 1 && !NPC.AnyNPCs(548))
			{
				DD2Event.StopInvasion(false);
			}
			if (Main.netMode == 1)
			{
				if (DD2Event._timeLeftUntilSpawningBegins > 0)
				{
					DD2Event._timeLeftUntilSpawningBegins--;
				}
				if (DD2Event._timeLeftUntilSpawningBegins < 0)
				{
					DD2Event._timeLeftUntilSpawningBegins = 0;
				}
				return;
			}
			if (DD2Event._timeLeftUntilSpawningBegins > 0)
			{
				DD2Event._timeLeftUntilSpawningBegins--;
				if (DD2Event._timeLeftUntilSpawningBegins == 0)
				{
					int num;
					int progressMax;
					int progress;
					DD2Event.GetInvasionStatus(out num, out progressMax, out progress, false);
					NetworkText invasionWaveText = Lang.GetInvasionWaveText(num, DD2Event.GetEnemiesForWave(num));
					WorldGen.BroadcastText(invasionWaveText, DD2Event.INFO_NEW_WAVE_COLOR);
					if (num == 7 && DD2Event.OngoingDifficulty == 3)
					{
						DD2Event.SummonBetsy();
					}
					if (Main.netMode != 1)
					{
						Main.ReportInvasionProgress(progress, progressMax, 3, num);
					}
					if (Main.netMode == 2)
					{
						NetMessage.SendData(78, -1, -1, null, Main.invasionProgress, (float)Main.invasionProgressMax, 3f, (float)num, 0, 0, 0);
					}
				}
			}
			if (DD2Event._timeLeftUntilSpawningBegins < 0)
			{
				DD2Event._timeLeftUntilSpawningBegins = 0;
			}
		}

		// Token: 0x06002569 RID: 9577 RVA: 0x0048575C File Offset: 0x0048395C
		public static void StartInvasion(int difficultyOverride = -1)
		{
			if (Main.netMode != 1)
			{
				DD2Event._crystalsDropping_toDrop = 0;
				DD2Event._crystalsDropping_alreadyDropped = 0;
				DD2Event._crystalsDropping_lastWave = 0;
				DD2Event._timeLeftUntilSpawningBegins = 0;
				DD2Event.Ongoing = true;
				DD2Event.FindProperDifficulty();
				if (difficultyOverride != -1)
				{
					DD2Event.OngoingDifficulty = difficultyOverride;
				}
				DD2Event._deadGoblinSpots.Clear();
				DD2Event._downedDarkMageT1 = false;
				DD2Event._downedOgreT2 = false;
				DD2Event._spawnedBetsyT3 = false;
				DD2Event.LostThisRun = false;
				DD2Event.WonThisRun = false;
				NPC.waveKills = 0f;
				NPC.waveNumber = 1;
				DD2Event.ClearAllTowersInGame();
				WorldGen.BroadcastText(NetworkText.FromKey("DungeonDefenders2.InvasionStart", new object[0]), DD2Event.INFO_START_INVASION_COLOR);
				NetMessage.SendData(7, -1, -1, null, 0, 0f, 0f, 0f, 0, 0, 0);
				if (Main.netMode != 1)
				{
					Main.ReportInvasionProgress(0, 1, 3, 1);
				}
				if (Main.netMode == 2)
				{
					NetMessage.SendData(78, -1, -1, null, 0, 1f, 3f, 1f, 0, 0, 0);
				}
				DD2Event.SetEnemySpawningOnHold(300);
				DD2Event.WipeEntities();
			}
		}

		// Token: 0x0600256A RID: 9578 RVA: 0x0048585C File Offset: 0x00483A5C
		public static void StopInvasion(bool win = false)
		{
			if (DD2Event.Ongoing)
			{
				if (win)
				{
					DD2Event.WinInvasionInternal();
				}
				DD2Event.Ongoing = false;
				DD2Event._deadGoblinSpots.Clear();
				if (Main.netMode != 1)
				{
					NPC.waveKills = 0f;
					NPC.waveNumber = 0;
					DD2Event.WipeEntities();
					NetMessage.SendData(7, -1, -1, null, 0, 0f, 0f, 0f, 0, 0, 0);
				}
			}
		}

		// Token: 0x0600256B RID: 9579 RVA: 0x004858C4 File Offset: 0x00483AC4
		private static void WinInvasionInternal()
		{
			if (DD2Event.OngoingDifficulty <= 1)
			{
				DD2Event.DownedInvasionT1 = true;
			}
			if (DD2Event.OngoingDifficulty <= 2)
			{
				DD2Event.DownedInvasionT2 = true;
			}
			if (DD2Event.OngoingDifficulty <= 3)
			{
				DD2Event.DownedInvasionT3 = true;
			}
			if (DD2Event.OngoingDifficulty == 1)
			{
				DD2Event.DropMedals(3);
			}
			if (DD2Event.OngoingDifficulty == 2)
			{
				DD2Event.DropMedals(15);
			}
			if (DD2Event.OngoingDifficulty == 3)
			{
				DD2Event.DropMedals(60);
			}
			WorldGen.BroadcastText(NetworkText.FromKey("DungeonDefenders2.InvasionWin", new object[0]), DD2Event.INFO_START_INVASION_COLOR);
		}

		// Token: 0x0600256C RID: 9580 RVA: 0x0001A548 File Offset: 0x00018748
		private static void FindProperDifficulty()
		{
			DD2Event.OngoingDifficulty = 1;
			if (DD2Event.ReadyForTier2)
			{
				DD2Event.OngoingDifficulty = 2;
			}
			if (DD2Event.ReadyForTier3)
			{
				DD2Event.OngoingDifficulty = 3;
			}
		}

		// Token: 0x0600256D RID: 9581 RVA: 0x00485944 File Offset: 0x00483B44
		public static void CheckProgress(int slainMonsterID)
		{
			if (Main.netMode == 1)
			{
				return;
			}
			if (!DD2Event.Ongoing)
			{
				return;
			}
			if (DD2Event.LostThisRun || DD2Event.WonThisRun)
			{
				return;
			}
			if (DD2Event.EnemySpawningIsOnHold)
			{
				return;
			}
			int num;
			int num2;
			int num3;
			DD2Event.GetInvasionStatus(out num, out num2, out num3, false);
			float num4 = (float)DD2Event.GetMonsterPointsWorth(slainMonsterID);
			float waveKills = NPC.waveKills;
			NPC.waveKills += num4;
			num3 += (int)num4;
			bool flag = false;
			int num5 = num;
			if (NPC.waveKills >= (float)num2 && num2 != 0)
			{
				NPC.waveKills = 0f;
				NPC.waveNumber++;
				flag = true;
				DD2Event.GetInvasionStatus(out num, out num2, out num3, true);
				if (DD2Event.WonThisRun)
				{
					if ((float)num3 != waveKills && num4 != 0f)
					{
						if (Main.netMode != 1)
						{
							Main.ReportInvasionProgress(num3, num2, 3, num);
						}
						if (Main.netMode == 2)
						{
							NetMessage.SendData(78, -1, -1, null, Main.invasionProgress, (float)Main.invasionProgressMax, 3f, (float)num, 0, 0, 0);
						}
					}
					return;
				}
				int num6 = num;
				WorldGen.BroadcastText(NetworkText.FromKey("DungeonDefenders2.WaveComplete", new object[0]), DD2Event.INFO_NEW_WAVE_COLOR);
				DD2Event.SetEnemySpawningOnHold(1800);
				if (DD2Event.OngoingDifficulty == 1)
				{
					if (num6 == 5)
					{
						DD2Event.DropMedals(1);
					}
					if (num6 == 4)
					{
						DD2Event.DropMedals(1);
					}
				}
				if (DD2Event.OngoingDifficulty == 2)
				{
					if (num6 == 7)
					{
						DD2Event.DropMedals(6);
					}
					if (num6 == 6)
					{
						DD2Event.DropMedals(3);
					}
					if (num6 == 5)
					{
						DD2Event.DropMedals(1);
					}
				}
				if (DD2Event.OngoingDifficulty == 3)
				{
					if (num6 == 7)
					{
						DD2Event.DropMedals(25);
					}
					if (num6 == 6)
					{
						DD2Event.DropMedals(11);
					}
					if (num6 == 5)
					{
						DD2Event.DropMedals(3);
					}
					if (num6 == 4)
					{
						DD2Event.DropMedals(1);
					}
				}
			}
			if ((float)num3 != waveKills)
			{
				if (flag)
				{
					int num7 = 1;
					int num8 = 1;
					if (Main.netMode != 1)
					{
						Main.ReportInvasionProgress(num7, num8, 3, num5);
					}
					if (Main.netMode == 2)
					{
						NetMessage.SendData(78, -1, -1, null, num7, (float)num8, 3f, (float)num5, 0, 0, 0);
						return;
					}
				}
				else
				{
					if (Main.netMode != 1)
					{
						Main.ReportInvasionProgress(num3, num2, 3, num);
					}
					if (Main.netMode == 2)
					{
						NetMessage.SendData(78, -1, -1, null, Main.invasionProgress, (float)Main.invasionProgressMax, 3f, (float)num, 0, 0, 0);
					}
				}
			}
		}

		// Token: 0x0600256E RID: 9582 RVA: 0x00485B54 File Offset: 0x00483D54
		public static void StartVictoryScene()
		{
			DD2Event.WonThisRun = true;
			int num = NPC.FindFirstNPC(548);
			if (num == -1)
			{
				return;
			}
			Main.npc[num].ai[1] = 2f;
			Main.npc[num].ai[0] = 2f;
			Main.npc[num].netUpdate = true;
			for (int i = 0; i < 200; i++)
			{
				if (Main.npc[i] != null && Main.npc[i].active && Main.npc[i].type == 549)
				{
					Main.npc[i].ai[0] = 0f;
					Main.npc[i].ai[1] = 1f;
					Main.npc[i].netUpdate = true;
				}
			}
		}

		// Token: 0x0600256F RID: 9583 RVA: 0x0001A56A File Offset: 0x0001876A
		public static void ReportLoss()
		{
			DD2Event.LostThisRun = true;
			DD2Event.SetEnemySpawningOnHold(30);
		}

		// Token: 0x06002570 RID: 9584 RVA: 0x00485C18 File Offset: 0x00483E18
		private static void GetInvasionStatus(out int currentWave, out int requiredKillCount, out int currentKillCount, bool currentlyInCheckProgress = false)
		{
			currentWave = NPC.waveNumber;
			requiredKillCount = 10;
			currentKillCount = (int)NPC.waveKills;
			int ongoingDifficulty = DD2Event.OngoingDifficulty;
			if (ongoingDifficulty == 2)
			{
				requiredKillCount = DD2Event.Difficulty_2_GetRequiredWaveKills(ref currentWave, ref currentKillCount, currentlyInCheckProgress);
				return;
			}
			if (ongoingDifficulty != 3)
			{
				requiredKillCount = DD2Event.Difficulty_1_GetRequiredWaveKills(ref currentWave, ref currentKillCount, currentlyInCheckProgress);
				return;
			}
			requiredKillCount = DD2Event.Difficulty_3_GetRequiredWaveKills(ref currentWave, ref currentKillCount, currentlyInCheckProgress);
		}

		// Token: 0x06002571 RID: 9585 RVA: 0x00485C68 File Offset: 0x00483E68
		private static short[] GetEnemiesForWave(int wave)
		{
			int ongoingDifficulty = DD2Event.OngoingDifficulty;
			if (ongoingDifficulty == 2)
			{
				return DD2Event.Difficulty_2_GetEnemiesForWave(wave);
			}
			if (ongoingDifficulty != 3)
			{
				return DD2Event.Difficulty_1_GetEnemiesForWave(wave);
			}
			return DD2Event.Difficulty_3_GetEnemiesForWave(wave);
		}

		// Token: 0x06002572 RID: 9586 RVA: 0x00485C9C File Offset: 0x00483E9C
		private static int GetMonsterPointsWorth(int slainMonsterID)
		{
			int ongoingDifficulty = DD2Event.OngoingDifficulty;
			if (ongoingDifficulty == 2)
			{
				return DD2Event.Difficulty_2_GetMonsterPointsWorth(slainMonsterID);
			}
			if (ongoingDifficulty != 3)
			{
				return DD2Event.Difficulty_1_GetMonsterPointsWorth(slainMonsterID);
			}
			return DD2Event.Difficulty_3_GetMonsterPointsWorth(slainMonsterID);
		}

		// Token: 0x06002573 RID: 9587 RVA: 0x00485CD0 File Offset: 0x00483ED0
		public static void SpawnMonsterFromGate(Vector2 gateBottom)
		{
			int ongoingDifficulty = DD2Event.OngoingDifficulty;
			if (ongoingDifficulty == 2)
			{
				DD2Event.Difficulty_2_SpawnMonsterFromGate(gateBottom);
				return;
			}
			if (ongoingDifficulty != 3)
			{
				DD2Event.Difficulty_1_SpawnMonsterFromGate(gateBottom);
				return;
			}
			DD2Event.Difficulty_3_SpawnMonsterFromGate(gateBottom);
		}

		// Token: 0x06002574 RID: 9588 RVA: 0x00485D04 File Offset: 0x00483F04
		public static void SummonCrystal(int x, int y)
		{
			if (Main.netMode == 1)
			{
				NetMessage.SendData(113, -1, -1, null, x, (float)y, 0f, 0f, 0, 0, 0);
				return;
			}
			DD2Event.SummonCrystalDirect(x, y);
		}

		// Token: 0x06002575 RID: 9589 RVA: 0x00485D3C File Offset: 0x00483F3C
		public static void SummonCrystalDirect(int x, int y)
		{
			if (NPC.AnyNPCs(548))
			{
				return;
			}
			Tile tileSafely = Framing.GetTileSafely(x, y);
			if (!tileSafely.active() || tileSafely.type != 466)
			{
				return;
			}
			Point point = new Point(x * 16, y * 16);
			point.X -= (int)(tileSafely.frameX / 18 * 16);
			point.Y -= (int)(tileSafely.frameY / 18 * 16);
			point.X += 40;
			point.Y += 64;
			DD2Event.StartInvasion(-1);
			NPC.NewNPC(point.X, point.Y, 548, 0, 0f, 0f, 0f, 0f, 255);
			DD2Event.DropStarterCrystals();
		}

		// Token: 0x06002576 RID: 9590 RVA: 0x00485E08 File Offset: 0x00484008
		public static bool WouldFailSpawningHere(int x, int y)
		{
			Point point;
			Point point2;
			StrayMethods.CheckArenaScore(new Point(x, y).ToWorldCoordinates(8f, 8f), out point, out point2, 5, 10);
			int num = point2.X - x;
			int num2 = x - point.X;
			return num < 60 || num2 < 60;
		}

		// Token: 0x06002577 RID: 9591 RVA: 0x00485E58 File Offset: 0x00484058
		public static void FailureMessage(int client)
		{
			LocalizedText text = Language.GetText("DungeonDefenders2.BartenderWarning");
			Color color = new Color(255, 255, 0);
			if (Main.netMode == 2)
			{
				NetMessage.SendChatMessageToClient(NetworkText.FromKey(text.Key, new object[0]), color, client);
				return;
			}
			Main.NewText(text.Value, color.R, color.G, color.B, false);
		}

		// Token: 0x06002578 RID: 9592 RVA: 0x00485EC4 File Offset: 0x004840C4
		public static void WipeEntities()
		{
			DD2Event.ClearAllTowersInGame();
			DD2Event.ClearAllDD2HostilesInGame();
			if (Main.netMode == 2)
			{
				NetMessage.SendData(114, -1, -1, null, 0, 0f, 0f, 0f, 0, 0, 0);
			}
		}

		// Token: 0x06002579 RID: 9593 RVA: 0x00485F00 File Offset: 0x00484100
		public static void ClearAllTowersInGame()
		{
			for (int i = 0; i < 1000; i++)
			{
				if (Main.projectile[i].active && ProjectileID.Sets.IsADD2Turret[Main.projectile[i].type])
				{
					Main.projectile[i].Kill();
				}
			}
		}

		// Token: 0x0600257A RID: 9594 RVA: 0x00485F4C File Offset: 0x0048414C
		public static void ClearAllDD2HostilesInGame()
		{
			for (int i = 0; i < 200; i++)
			{
				if (Main.npc[i].active && NPCID.Sets.BelongsToInvasionOldOnesArmy[Main.npc[i].type])
				{
					Main.npc[i].active = false;
					if (Main.netMode == 2)
					{
						NetMessage.SendData(23, -1, -1, null, i, 0f, 0f, 0f, 0, 0, 0);
					}
				}
			}
		}

		// Token: 0x0600257B RID: 9595 RVA: 0x00485FC0 File Offset: 0x004841C0
		public static void ClearAllDD2EnergyCrystalsInGame()
		{
			for (int i = 0; i < 400; i++)
			{
				Item item = Main.item[i];
				if (item.active && item.type == 3822)
				{
					item.active = false;
					if (Main.netMode == 2)
					{
						NetMessage.SendData(21, -1, -1, null, i, 0f, 0f, 0f, 0, 0, 0);
					}
				}
			}
		}

		// Token: 0x0600257C RID: 9596 RVA: 0x0001A579 File Offset: 0x00018779
		public static void AnnounceGoblinDeath(NPC n)
		{
			DD2Event._deadGoblinSpots.Add(n.Bottom);
		}

		// Token: 0x0600257D RID: 9597 RVA: 0x00486028 File Offset: 0x00484228
		public static bool CanRaiseGoblinsHere(Vector2 spot)
		{
			int num = 0;
			foreach (Vector2 value in DD2Event._deadGoblinSpots)
			{
				if (Vector2.DistanceSquared(value, spot) <= 640000f)
				{
					num++;
					if (num >= 3)
					{
						return true;
					}
				}
			}
			return false;
		}

		// Token: 0x0600257E RID: 9598 RVA: 0x00486094 File Offset: 0x00484294
		public static void RaiseGoblins(Vector2 spot)
		{
			List<Vector2> list = new List<Vector2>();
			foreach (Vector2 vector in DD2Event._deadGoblinSpots)
			{
				if (Vector2.DistanceSquared(vector, spot) <= 722500f)
				{
					list.Add(vector);
				}
			}
			foreach (Vector2 item in list)
			{
				DD2Event._deadGoblinSpots.Remove(item);
			}
			int num = 0;
			foreach (Vector2 vec in list)
			{
				Point origin = vec.ToTileCoordinates();
				origin.X += Main.rand.Next(-15, 16);
				Point point;
				if (WorldUtils.Find(origin, Searches.Chain(new Searches.Down(50), new GenCondition[]
				{
					new Conditions.IsSolid()
				}), out point))
				{
					if (DD2Event.OngoingDifficulty == 3)
					{
						NPC.NewNPC(point.X * 16 + 8, point.Y * 16, 567, 0, 0f, 0f, 0f, 0f, 255);
					}
					else
					{
						NPC.NewNPC(point.X * 16 + 8, point.Y * 16, 566, 0, 0f, 0f, 0f, 0f, 255);
					}
					if (++num >= 8)
					{
						break;
					}
				}
			}
		}

		// Token: 0x0600257F RID: 9599 RVA: 0x00486254 File Offset: 0x00484454
		public static void FindArenaHitbox()
		{
			if (DD2Event._arenaHitboxingCooldown > 0)
			{
				DD2Event._arenaHitboxingCooldown--;
				return;
			}
			DD2Event._arenaHitboxingCooldown = 60;
			Vector2 vector = new Vector2(float.MaxValue, float.MaxValue);
			Vector2 vector2 = new Vector2(0f, 0f);
			for (int i = 0; i < 200; i++)
			{
				NPC npc = Main.npc[i];
				if (npc.active && (npc.type == 549 || npc.type == 548))
				{
					Vector2 vector3 = npc.TopLeft;
					if (vector.X > vector3.X)
					{
						vector.X = vector3.X;
					}
					if (vector.Y > vector3.Y)
					{
						vector.Y = vector3.Y;
					}
					vector3 = npc.BottomRight;
					if (vector2.X < vector3.X)
					{
						vector2.X = vector3.X;
					}
					if (vector2.Y < vector3.Y)
					{
						vector2.Y = vector3.Y;
					}
				}
			}
			Vector2 value = new Vector2(16f, 16f) * 50f;
			vector -= value;
			vector2 += value;
			Vector2 vector4 = vector2 - vector;
			DD2Event.ArenaHitbox.X = (int)vector.X;
			DD2Event.ArenaHitbox.Y = (int)vector.Y;
			DD2Event.ArenaHitbox.Width = (int)vector4.X;
			DD2Event.ArenaHitbox.Height = (int)vector4.Y;
		}

		// Token: 0x06002580 RID: 9600 RVA: 0x0001A58B File Offset: 0x0001878B
		public static bool ShouldBlockBuilding(Vector2 worldPosition)
		{
			return DD2Event.ArenaHitbox.Contains(worldPosition.ToPoint());
		}

		// Token: 0x06002581 RID: 9601 RVA: 0x004863EC File Offset: 0x004845EC
		public static void DropMedals(int numberOfMedals)
		{
			for (int i = 0; i < 200; i++)
			{
				if (Main.npc[i].active && Main.npc[i].type == 548)
				{
					Main.npc[i].DropItemInstanced(Main.npc[i].position, Main.npc[i].Size, 3817, numberOfMedals, false);
				}
			}
		}

		// Token: 0x06002582 RID: 9602 RVA: 0x00486458 File Offset: 0x00484658
		public static bool ShouldDropCrystals()
		{
			int num;
			int num2;
			int num3;
			DD2Event.GetInvasionStatus(out num, out num2, out num3, false);
			if (DD2Event._crystalsDropping_lastWave < num)
			{
				DD2Event._crystalsDropping_lastWave++;
				if (DD2Event._crystalsDropping_alreadyDropped > 0)
				{
					DD2Event._crystalsDropping_alreadyDropped -= DD2Event._crystalsDropping_toDrop;
				}
				if (DD2Event.OngoingDifficulty == 1)
				{
					switch (num)
					{
					case 1:
						DD2Event._crystalsDropping_toDrop = 20;
						break;
					case 2:
						DD2Event._crystalsDropping_toDrop = 20;
						break;
					case 3:
						DD2Event._crystalsDropping_toDrop = 30;
						break;
					case 4:
						DD2Event._crystalsDropping_toDrop = 30;
						break;
					case 5:
						DD2Event._crystalsDropping_toDrop = 40;
						break;
					}
				}
				else if (DD2Event.OngoingDifficulty == 2)
				{
					switch (num)
					{
					case 1:
						DD2Event._crystalsDropping_toDrop = 20;
						break;
					case 2:
						DD2Event._crystalsDropping_toDrop = 20;
						break;
					case 3:
						DD2Event._crystalsDropping_toDrop = 20;
						break;
					case 4:
						DD2Event._crystalsDropping_toDrop = 20;
						break;
					case 5:
						DD2Event._crystalsDropping_toDrop = 20;
						break;
					case 6:
						DD2Event._crystalsDropping_toDrop = 30;
						break;
					case 7:
						DD2Event._crystalsDropping_toDrop = 30;
						break;
					}
				}
				else if (DD2Event.OngoingDifficulty == 3)
				{
					switch (num)
					{
					case 1:
						DD2Event._crystalsDropping_toDrop = 20;
						break;
					case 2:
						DD2Event._crystalsDropping_toDrop = 20;
						break;
					case 3:
						DD2Event._crystalsDropping_toDrop = 20;
						break;
					case 4:
						DD2Event._crystalsDropping_toDrop = 20;
						break;
					case 5:
						DD2Event._crystalsDropping_toDrop = 30;
						break;
					case 6:
						DD2Event._crystalsDropping_toDrop = 30;
						break;
					case 7:
						DD2Event._crystalsDropping_toDrop = 30;
						break;
					}
				}
			}
			float num4 = (float)num3 / (float)num2;
			if ((float)DD2Event._crystalsDropping_alreadyDropped < (float)DD2Event._crystalsDropping_toDrop * num4)
			{
				DD2Event._crystalsDropping_alreadyDropped++;
				return true;
			}
			return false;
		}

		// Token: 0x06002583 RID: 9603 RVA: 0x00486614 File Offset: 0x00484814
		private static void SummonBetsy()
		{
			if (DD2Event._spawnedBetsyT3)
			{
				return;
			}
			if (NPC.AnyNPCs(551))
			{
				return;
			}
			Vector2 center = new Vector2(1f, 1f);
			int num = NPC.FindFirstNPC(548);
			if (num != -1)
			{
				center = Main.npc[num].Center;
			}
			int plr = (int)Player.FindClosest(center, 1, 1);
			NPC.SpawnOnPlayer(plr, 551);
			DD2Event._spawnedBetsyT3 = true;
		}

		// Token: 0x06002584 RID: 9604 RVA: 0x00486680 File Offset: 0x00484880
		private static void DropStarterCrystals()
		{
			for (int i = 0; i < 200; i++)
			{
				if (Main.npc[i].active && Main.npc[i].type == 548)
				{
					for (int j = 0; j < 5; j++)
					{
						Item.NewItem(Main.npc[i].position, Main.npc[i].width, Main.npc[i].height, 3822, 2, false, 0, false, false);
					}
					return;
				}
			}
		}

		// Token: 0x06002585 RID: 9605 RVA: 0x00486700 File Offset: 0x00484900
		private static void SetEnemySpawningOnHold(int forHowLong)
		{
			DD2Event._timeLeftUntilSpawningBegins = forHowLong;
			if (Main.netMode == 2)
			{
				NetMessage.SendData(116, -1, -1, null, DD2Event._timeLeftUntilSpawningBegins, 0f, 0f, 0f, 0, 0, 0);
			}
		}

		// Token: 0x06002586 RID: 9606 RVA: 0x0048673C File Offset: 0x0048493C
		private static short[] Difficulty_1_GetEnemiesForWave(int wave)
		{
			DD2Event.LaneSpawnRate = 60;
			switch (wave)
			{
			case 1:
				DD2Event.LaneSpawnRate = 90;
				return new short[]
				{
					552
				};
			case 2:
				return new short[]
				{
					552,
					555
				};
			case 3:
				DD2Event.LaneSpawnRate = 55;
				return new short[]
				{
					552,
					555,
					561
				};
			case 4:
				DD2Event.LaneSpawnRate = 50;
				return new short[]
				{
					552,
					555,
					561,
					558
				};
			case 5:
				DD2Event.LaneSpawnRate = 40;
				return new short[]
				{
					552,
					555,
					561,
					558,
					564
				};
			default:
				return new short[]
				{
					552
				};
			}
		}

		// Token: 0x06002587 RID: 9607 RVA: 0x004867F4 File Offset: 0x004849F4
		private static int Difficulty_1_GetRequiredWaveKills(ref int waveNumber, ref int currentKillCount, bool currentlyInCheckProgress)
		{
			switch (waveNumber)
			{
			case -1:
				return 0;
			case 1:
				return 60;
			case 2:
				return 80;
			case 3:
				return 100;
			case 4:
				DD2Event._deadGoblinSpots.Clear();
				return 120;
			case 5:
				if (!DD2Event._downedDarkMageT1 && currentKillCount > 139)
				{
					currentKillCount = 139;
				}
				return 140;
			case 6:
				waveNumber = 5;
				currentKillCount = 1;
				if (currentlyInCheckProgress)
				{
					DD2Event.StartVictoryScene();
				}
				return 1;
			}
			return 10;
		}

		// Token: 0x06002588 RID: 9608 RVA: 0x00486878 File Offset: 0x00484A78
		private static void Difficulty_1_SpawnMonsterFromGate(Vector2 gateBottom)
		{
			int x = (int)gateBottom.X;
			int y = (int)gateBottom.Y;
			int num = 50;
			int num2 = 6;
			if (NPC.waveNumber > 4)
			{
				num2 = 12;
			}
			else if (NPC.waveNumber > 3)
			{
				num2 = 8;
			}
			int num3 = 6;
			if (NPC.waveNumber > 4)
			{
				num3 = 8;
			}
			for (int i = 1; i < Main.ActivePlayersCount; i++)
			{
				num = (int)((double)num * 1.3);
				num2 = (int)((double)num2 * 1.3);
				num3 = (int)((double)num3 * 1.3);
			}
			int num4 = 200;
			switch (NPC.waveNumber)
			{
			case 1:
				if (NPC.CountNPCS(552) + NPC.CountNPCS(555) < num)
				{
					num4 = NPC.NewNPC(x, y, 552, 0, 0f, 0f, 0f, 0f, 255);
				}
				break;
			case 2:
				if (NPC.CountNPCS(552) + NPC.CountNPCS(555) < num)
				{
					if (Main.rand.Next(7) == 0)
					{
						num4 = NPC.NewNPC(x, y, 555, 0, 0f, 0f, 0f, 0f, 255);
					}
					else
					{
						num4 = NPC.NewNPC(x, y, 552, 0, 0f, 0f, 0f, 0f, 255);
					}
				}
				break;
			case 3:
				if (Main.rand.Next(6) == 0 && NPC.CountNPCS(561) < num2)
				{
					num4 = NPC.NewNPC(x, y, 561, 0, 0f, 0f, 0f, 0f, 255);
				}
				else if (NPC.CountNPCS(552) + NPC.CountNPCS(555) < num)
				{
					if (Main.rand.Next(5) == 0)
					{
						num4 = NPC.NewNPC(x, y, 555, 0, 0f, 0f, 0f, 0f, 255);
					}
					else
					{
						num4 = NPC.NewNPC(x, y, 552, 0, 0f, 0f, 0f, 0f, 255);
					}
				}
				break;
			case 4:
				if (Main.rand.Next(12) == 0 && NPC.CountNPCS(558) < num3)
				{
					num4 = NPC.NewNPC(x, y, 558, 0, 0f, 0f, 0f, 0f, 255);
				}
				else if (Main.rand.Next(5) == 0 && NPC.CountNPCS(561) < num2)
				{
					num4 = NPC.NewNPC(x, y, 561, 0, 0f, 0f, 0f, 0f, 255);
				}
				else if (NPC.CountNPCS(552) + NPC.CountNPCS(555) < num)
				{
					if (Main.rand.Next(5) == 0)
					{
						num4 = NPC.NewNPC(x, y, 555, 0, 0f, 0f, 0f, 0f, 255);
					}
					else
					{
						num4 = NPC.NewNPC(x, y, 552, 0, 0f, 0f, 0f, 0f, 255);
					}
				}
				break;
			case 5:
			{
				int num5;
				int num6;
				int num7;
				DD2Event.GetInvasionStatus(out num5, out num6, out num7, false);
				if ((float)num7 > (float)num6 * 0.5f && !NPC.AnyNPCs(564))
				{
					num4 = NPC.NewNPC(x, y, 564, 0, 0f, 0f, 0f, 0f, 255);
				}
				if (Main.rand.Next(10) == 0 && NPC.CountNPCS(558) < num3)
				{
					num4 = NPC.NewNPC(x, y, 558, 0, 0f, 0f, 0f, 0f, 255);
				}
				else if (Main.rand.Next(4) == 0 && NPC.CountNPCS(561) < num2)
				{
					num4 = NPC.NewNPC(x, y, 561, 0, 0f, 0f, 0f, 0f, 255);
				}
				else if (NPC.CountNPCS(552) + NPC.CountNPCS(555) < num)
				{
					if (Main.rand.Next(4) == 0)
					{
						num4 = NPC.NewNPC(x, y, 555, 0, 0f, 0f, 0f, 0f, 255);
					}
					else
					{
						num4 = NPC.NewNPC(x, y, 552, 0, 0f, 0f, 0f, 0f, 255);
					}
				}
				break;
			}
			default:
				num4 = NPC.NewNPC(x, y, 552, 0, 0f, 0f, 0f, 0f, 255);
				break;
			}
			if (Main.netMode == 2 && num4 < 200)
			{
				NetMessage.SendData(23, -1, -1, null, num4, 0f, 0f, 0f, 0, 0, 0);
			}
		}

		// Token: 0x06002589 RID: 9609 RVA: 0x00486D88 File Offset: 0x00484F88
		private static int Difficulty_1_GetMonsterPointsWorth(int slainMonsterID)
		{
			if (NPC.waveNumber != 5 || NPC.waveKills < 139f)
			{
				if (slainMonsterID - 551 > 14 && slainMonsterID - 568 > 10)
				{
					return 0;
				}
				if (NPC.waveNumber == 5 && NPC.waveKills == 138f)
				{
					return 1;
				}
				if (!Main.expertMode)
				{
					return 1;
				}
				return 2;
			}
			else
			{
				if (slainMonsterID == 564 || slainMonsterID == 565)
				{
					DD2Event._downedDarkMageT1 = true;
					return 1;
				}
				return 0;
			}
		}

		// Token: 0x0600258A RID: 9610 RVA: 0x00486DFC File Offset: 0x00484FFC
		private static short[] Difficulty_2_GetEnemiesForWave(int wave)
		{
			DD2Event.LaneSpawnRate = 60;
			switch (wave)
			{
			case 1:
				DD2Event.LaneSpawnRate = 90;
				return new short[]
				{
					553,
					562
				};
			case 2:
				DD2Event.LaneSpawnRate = 70;
				return new short[]
				{
					553,
					562,
					572
				};
			case 3:
				return new short[]
				{
					553,
					556,
					562,
					559,
					572
				};
			case 4:
				DD2Event.LaneSpawnRate = 55;
				return new short[]
				{
					553,
					559,
					570,
					572,
					562
				};
			case 5:
				DD2Event.LaneSpawnRate = 50;
				return new short[]
				{
					553,
					556,
					559,
					572,
					574,
					570
				};
			case 6:
				DD2Event.LaneSpawnRate = 45;
				return new short[]
				{
					553,
					556,
					562,
					559,
					568,
					570,
					572,
					574
				};
			case 7:
				DD2Event.LaneSpawnRate = 42;
				return new short[]
				{
					553,
					556,
					572,
					559,
					568,
					574,
					570,
					576
				};
			default:
				return new short[]
				{
					553
				};
			}
		}

		// Token: 0x0600258B RID: 9611 RVA: 0x00486EF4 File Offset: 0x004850F4
		private static int Difficulty_2_GetRequiredWaveKills(ref int waveNumber, ref int currentKillCount, bool currentlyInCheckProgress)
		{
			switch (waveNumber)
			{
			case -1:
				return 0;
			case 1:
				return 60;
			case 2:
				return 80;
			case 3:
				return 100;
			case 4:
				return 120;
			case 5:
				return 140;
			case 6:
				return 180;
			case 7:
				if (!DD2Event._downedOgreT2 && currentKillCount > 219)
				{
					currentKillCount = 219;
				}
				return 220;
			case 8:
				waveNumber = 7;
				currentKillCount = 1;
				if (currentlyInCheckProgress)
				{
					DD2Event.StartVictoryScene();
				}
				return 1;
			}
			return 10;
		}

		// Token: 0x0600258C RID: 9612 RVA: 0x00486F80 File Offset: 0x00485180
		private static int Difficulty_2_GetMonsterPointsWorth(int slainMonsterID)
		{
			if (NPC.waveNumber != 7 || NPC.waveKills < 219f)
			{
				if (slainMonsterID - 551 > 14 && slainMonsterID - 568 > 10)
				{
					return 0;
				}
				if (NPC.waveNumber == 7 && NPC.waveKills == 218f)
				{
					return 1;
				}
				if (!Main.expertMode)
				{
					return 1;
				}
				return 2;
			}
			else
			{
				if (slainMonsterID == 576 || slainMonsterID == 577)
				{
					DD2Event._downedOgreT2 = true;
					return 1;
				}
				return 0;
			}
		}

		// Token: 0x0600258D RID: 9613 RVA: 0x00486FF4 File Offset: 0x004851F4
		private static void Difficulty_2_SpawnMonsterFromGate(Vector2 gateBottom)
		{
			int x = (int)gateBottom.X;
			int y = (int)gateBottom.Y;
			int num = 50;
			int num2 = 5;
			if (NPC.waveNumber > 1)
			{
				num2 = 8;
			}
			if (NPC.waveNumber > 3)
			{
				num2 = 10;
			}
			if (NPC.waveNumber > 5)
			{
				num2 = 12;
			}
			int num3 = 5;
			if (NPC.waveNumber > 4)
			{
				num3 = 7;
			}
			int num4 = 2;
			int num5 = 8;
			if (NPC.waveNumber > 3)
			{
				num5 = 12;
			}
			int num6 = 3;
			if (NPC.waveNumber > 5)
			{
				num6 = 5;
			}
			for (int i = 1; i < Main.ActivePlayersCount; i++)
			{
				num = (int)((double)num * 1.3);
				num2 = (int)((double)num2 * 1.3);
				num5 = (int)((double)num * 1.3);
				num6 = (int)((double)num * 1.35);
			}
			int num7 = 200;
			int num8 = 200;
			switch (NPC.waveNumber)
			{
			case 1:
				if (Main.rand.Next(20) == 0 && NPC.CountNPCS(562) < num2)
				{
					num7 = NPC.NewNPC(x, y, 562, 0, 0f, 0f, 0f, 0f, 255);
				}
				else if (NPC.CountNPCS(553) < num)
				{
					num7 = NPC.NewNPC(x, y, 553, 0, 0f, 0f, 0f, 0f, 255);
				}
				break;
			case 2:
				if (Main.rand.Next(3) == 0 && NPC.CountNPCS(572) < num5)
				{
					num7 = NPC.NewNPC(x, y, 572, 0, 0f, 0f, 0f, 0f, 255);
				}
				else if (Main.rand.Next(8) == 0 && NPC.CountNPCS(562) < num2)
				{
					num7 = NPC.NewNPC(x, y, 562, 0, 0f, 0f, 0f, 0f, 255);
				}
				else if (NPC.CountNPCS(553) < num)
				{
					num7 = NPC.NewNPC(x, y, 553, 0, 0f, 0f, 0f, 0f, 255);
				}
				break;
			case 3:
				if (Main.rand.Next(7) == 0 && NPC.CountNPCS(572) < num5)
				{
					num7 = NPC.NewNPC(x, y, 572, 0, 0f, 0f, 0f, 0f, 255);
				}
				else if (Main.rand.Next(10) == 0 && NPC.CountNPCS(559) < num3)
				{
					num7 = NPC.NewNPC(x, y, 559, 0, 0f, 0f, 0f, 0f, 255);
				}
				else if (Main.rand.Next(8) == 0 && NPC.CountNPCS(562) < num2)
				{
					num7 = NPC.NewNPC(x, y, 562, 0, 0f, 0f, 0f, 0f, 255);
				}
				else if (NPC.CountNPCS(553) + NPC.CountNPCS(556) < num)
				{
					if (Main.rand.Next(4) == 0)
					{
						num7 = NPC.NewNPC(x, y, 556, 0, 0f, 0f, 0f, 0f, 255);
					}
					num8 = NPC.NewNPC(x, y, 553, 0, 0f, 0f, 0f, 0f, 255);
				}
				break;
			case 4:
				if (Main.rand.Next(10) == 0 && NPC.CountNPCS(570) < num6)
				{
					num7 = NPC.NewNPC(x, y, 570, 0, 0f, 0f, 0f, 0f, 255);
				}
				else if (Main.rand.Next(12) == 0 && NPC.CountNPCS(559) < num3)
				{
					num7 = NPC.NewNPC(x, y, 559, 0, 0f, 0f, 0f, 0f, 255);
				}
				else if (Main.rand.Next(6) == 0 && NPC.CountNPCS(562) < num2)
				{
					num7 = NPC.NewNPC(x, y, 562, 0, 0f, 0f, 0f, 0f, 255);
				}
				else if (Main.rand.Next(3) == 0 && NPC.CountNPCS(572) < num5)
				{
					num7 = NPC.NewNPC(x, y, 572, 0, 0f, 0f, 0f, 0f, 255);
				}
				else if (NPC.CountNPCS(553) < num)
				{
					num7 = NPC.NewNPC(x, y, 553, 0, 0f, 0f, 0f, 0f, 255);
				}
				break;
			case 5:
				if (Main.rand.Next(7) == 0 && NPC.CountNPCS(570) < num6)
				{
					num7 = NPC.NewNPC(x, y, 570, 0, 0f, 0f, 0f, 0f, 255);
				}
				else if (Main.rand.Next(10) == 0 && NPC.CountNPCS(559) < num3)
				{
					num7 = NPC.NewNPC(x, y, 559, 0, 0f, 0f, 0f, 0f, 255);
				}
				else if (Main.rand.Next(4) == 0 && NPC.CountNPCS(572) + NPC.CountNPCS(574) < num5)
				{
					if (Main.rand.Next(2) == 0)
					{
						num7 = NPC.NewNPC(x, y, 572, 0, 0f, 0f, 0f, 0f, 255);
					}
					else
					{
						num7 = NPC.NewNPC(x, y, 574, 0, 0f, 0f, 0f, 0f, 255);
					}
				}
				else if (NPC.CountNPCS(553) + NPC.CountNPCS(556) < num)
				{
					if (Main.rand.Next(3) == 0)
					{
						num7 = NPC.NewNPC(x, y, 556, 0, 0f, 0f, 0f, 0f, 255);
					}
					num8 = NPC.NewNPC(x, y, 553, 0, 0f, 0f, 0f, 0f, 255);
				}
				break;
			case 6:
				if (Main.rand.Next(7) == 0 && NPC.CountNPCS(570) < num6)
				{
					num7 = NPC.NewNPC(x, y, 570, 0, 0f, 0f, 0f, 0f, 255);
				}
				else if (Main.rand.Next(17) == 0 && NPC.CountNPCS(568) < num4)
				{
					num7 = NPC.NewNPC(x, y, 568, 0, 0f, 0f, 0f, 0f, 255);
				}
				else if (Main.rand.Next(5) == 0 && NPC.CountNPCS(572) + NPC.CountNPCS(574) < num5)
				{
					if (Main.rand.Next(2) != 0)
					{
						num7 = NPC.NewNPC(x, y, 572, 0, 0f, 0f, 0f, 0f, 255);
					}
					else
					{
						num7 = NPC.NewNPC(x, y, 574, 0, 0f, 0f, 0f, 0f, 255);
					}
				}
				else if (Main.rand.Next(9) == 0 && NPC.CountNPCS(559) < num3)
				{
					num7 = NPC.NewNPC(x, y, 559, 0, 0f, 0f, 0f, 0f, 255);
				}
				else if (Main.rand.Next(3) == 0 && NPC.CountNPCS(562) < num2)
				{
					num7 = NPC.NewNPC(x, y, 562, 0, 0f, 0f, 0f, 0f, 255);
				}
				else if (NPC.CountNPCS(553) + NPC.CountNPCS(556) < num)
				{
					if (Main.rand.Next(3) != 0)
					{
						num7 = NPC.NewNPC(x, y, 556, 0, 0f, 0f, 0f, 0f, 255);
					}
					num8 = NPC.NewNPC(x, y, 553, 0, 0f, 0f, 0f, 0f, 255);
				}
				break;
			case 7:
			{
				int num9;
				int num10;
				int num11;
				DD2Event.GetInvasionStatus(out num9, out num10, out num11, false);
				if ((float)num11 > (float)num10 * 0.1f && !NPC.AnyNPCs(576))
				{
					num7 = NPC.NewNPC(x, y, 576, 0, 0f, 0f, 0f, 0f, 255);
				}
				else if (Main.rand.Next(7) == 0 && NPC.CountNPCS(570) < num6)
				{
					num7 = NPC.NewNPC(x, y, 570, 0, 0f, 0f, 0f, 0f, 255);
				}
				else if (Main.rand.Next(17) == 0 && NPC.CountNPCS(568) < num4)
				{
					num7 = NPC.NewNPC(x, y, 568, 0, 0f, 0f, 0f, 0f, 255);
				}
				else if (Main.rand.Next(7) == 0 && NPC.CountNPCS(572) + NPC.CountNPCS(574) < num5)
				{
					if (Main.rand.Next(3) != 0)
					{
						num7 = NPC.NewNPC(x, y, 572, 0, 0f, 0f, 0f, 0f, 255);
					}
					else
					{
						num7 = NPC.NewNPC(x, y, 574, 0, 0f, 0f, 0f, 0f, 255);
					}
				}
				else if (Main.rand.Next(11) == 0 && NPC.CountNPCS(559) < num3)
				{
					num7 = NPC.NewNPC(x, y, 559, 0, 0f, 0f, 0f, 0f, 255);
				}
				else if (NPC.CountNPCS(553) + NPC.CountNPCS(556) < num)
				{
					if (Main.rand.Next(2) == 0)
					{
						num7 = NPC.NewNPC(x, y, 556, 0, 0f, 0f, 0f, 0f, 255);
					}
					num8 = NPC.NewNPC(x, y, 553, 0, 0f, 0f, 0f, 0f, 255);
				}
				break;
			}
			default:
				num7 = NPC.NewNPC(x, y, 553, 0, 0f, 0f, 0f, 0f, 255);
				break;
			}
			if (Main.netMode == 2 && num7 < 200)
			{
				NetMessage.SendData(23, -1, -1, null, num7, 0f, 0f, 0f, 0, 0, 0);
			}
			if (Main.netMode == 2 && num8 < 200)
			{
				NetMessage.SendData(23, -1, -1, null, num8, 0f, 0f, 0f, 0, 0, 0);
			}
		}

		// Token: 0x0600258E RID: 9614 RVA: 0x00487B80 File Offset: 0x00485D80
		private static short[] Difficulty_3_GetEnemiesForWave(int wave)
		{
			DD2Event.LaneSpawnRate = 60;
			switch (wave)
			{
			case 1:
				DD2Event.LaneSpawnRate = 85;
				return new short[]
				{
					554,
					557,
					563
				};
			case 2:
				DD2Event.LaneSpawnRate = 75;
				return new short[]
				{
					554,
					557,
					563,
					573,
					578
				};
			case 3:
				DD2Event.LaneSpawnRate = 60;
				return new short[]
				{
					554,
					563,
					560,
					573,
					571
				};
			case 4:
				DD2Event.LaneSpawnRate = 60;
				return new short[]
				{
					554,
					560,
					571,
					573,
					563,
					575,
					565
				};
			case 5:
				DD2Event.LaneSpawnRate = 55;
				return new short[]
				{
					554,
					557,
					573,
					575,
					571,
					569,
					577
				};
			case 6:
				DD2Event.LaneSpawnRate = 60;
				return new short[]
				{
					554,
					557,
					563,
					560,
					569,
					571,
					577,
					565
				};
			case 7:
				DD2Event.LaneSpawnRate = 90;
				return new short[]
				{
					554,
					557,
					563,
					569,
					571,
					551
				};
			default:
				return new short[]
				{
					554
				};
			}
		}

		// Token: 0x0600258F RID: 9615 RVA: 0x00487C7C File Offset: 0x00485E7C
		private static int Difficulty_3_GetRequiredWaveKills(ref int waveNumber, ref int currentKillCount, bool currentlyInCheckProgress)
		{
			switch (waveNumber)
			{
			case -1:
				return 0;
			case 1:
				return 60;
			case 2:
				return 80;
			case 3:
				return 100;
			case 4:
				return 120;
			case 5:
				return 140;
			case 6:
				return 180;
			case 7:
			{
				int num = NPC.FindFirstNPC(551);
				if (num == -1)
				{
					return 1;
				}
				currentKillCount = 100 - (int)((float)Main.npc[num].life / (float)Main.npc[num].lifeMax * 100f);
				return 100;
			}
			case 8:
				waveNumber = 7;
				currentKillCount = 1;
				if (currentlyInCheckProgress)
				{
					DD2Event.StartVictoryScene();
				}
				return 1;
			}
			return 10;
		}

		// Token: 0x06002590 RID: 9616 RVA: 0x0001A59D File Offset: 0x0001879D
		private static int Difficulty_3_GetMonsterPointsWorth(int slainMonsterID)
		{
			if (NPC.waveNumber != 7)
			{
				if (slainMonsterID - 551 > 14 && slainMonsterID - 568 > 10)
				{
					return 0;
				}
				if (!Main.expertMode)
				{
					return 1;
				}
				return 2;
			}
			else
			{
				if (slainMonsterID == 551)
				{
					return 1;
				}
				return 0;
			}
		}

		// Token: 0x06002591 RID: 9617 RVA: 0x00487D28 File Offset: 0x00485F28
		private static void Difficulty_3_SpawnMonsterFromGate(Vector2 gateBottom)
		{
			int x = (int)gateBottom.X;
			int y = (int)gateBottom.Y;
			int num = 60;
			int num2 = 7;
			if (NPC.waveNumber > 1)
			{
				num2 = 9;
			}
			if (NPC.waveNumber > 3)
			{
				num2 = 12;
			}
			if (NPC.waveNumber > 5)
			{
				num2 = 15;
			}
			int num3 = 7;
			if (NPC.waveNumber > 4)
			{
				num3 = 10;
			}
			int num4 = 2;
			if (NPC.waveNumber > 5)
			{
				num4 = 3;
			}
			int num5 = 12;
			if (NPC.waveNumber > 3)
			{
				num5 = 18;
			}
			int num6 = 4;
			if (NPC.waveNumber > 5)
			{
				num6 = 6;
			}
			int num7 = 4;
			for (int i = 1; i < Main.ActivePlayersCount; i++)
			{
				num = (int)((double)num * 1.3);
				num2 = (int)((double)num2 * 1.3);
				num5 = (int)((double)num * 1.3);
				num6 = (int)((double)num * 1.35);
				num7 = (int)((double)num7 * 1.3);
			}
			int num8 = 200;
			int num9 = 200;
			switch (NPC.waveNumber)
			{
			case 1:
				if (Main.rand.Next(18) == 0 && NPC.CountNPCS(563) < num2)
				{
					num8 = NPC.NewNPC(x, y, 563, 0, 0f, 0f, 0f, 0f, 255);
				}
				else if (NPC.CountNPCS(554) < num)
				{
					if (Main.rand.Next(7) == 0)
					{
						num8 = NPC.NewNPC(x, y, 557, 0, 0f, 0f, 0f, 0f, 255);
					}
					num9 = NPC.NewNPC(x, y, 554, 0, 0f, 0f, 0f, 0f, 255);
				}
				break;
			case 2:
				if (Main.rand.Next(3) == 0 && NPC.CountNPCS(578) < num7)
				{
					num8 = NPC.NewNPC(x, y, 578, 0, 0f, 0f, 0f, 0f, 255);
				}
				else if (Main.rand.Next(7) == 0 && NPC.CountNPCS(563) < num2)
				{
					num8 = NPC.NewNPC(x, y, 563, 0, 0f, 0f, 0f, 0f, 255);
				}
				else if (Main.rand.Next(3) == 0 && NPC.CountNPCS(573) < num5)
				{
					num8 = NPC.NewNPC(x, y, 573, 0, 0f, 0f, 0f, 0f, 255);
				}
				else if (NPC.CountNPCS(554) < num)
				{
					if (Main.rand.Next(4) == 0)
					{
						num8 = NPC.NewNPC(x, y, 557, 0, 0f, 0f, 0f, 0f, 255);
					}
					num9 = NPC.NewNPC(x, y, 554, 0, 0f, 0f, 0f, 0f, 255);
				}
				break;
			case 3:
				if (Main.rand.Next(13) == 0 && NPC.CountNPCS(571) < num6)
				{
					num8 = NPC.NewNPC(x, y, 571, 0, 0f, 0f, 0f, 0f, 255);
				}
				else if (Main.rand.Next(7) == 0 && NPC.CountNPCS(573) < num5)
				{
					num8 = NPC.NewNPC(x, y, 573, 0, 0f, 0f, 0f, 0f, 255);
				}
				else if (Main.rand.Next(10) == 0 && NPC.CountNPCS(560) < num3)
				{
					num8 = NPC.NewNPC(x, y, 560, 0, 0f, 0f, 0f, 0f, 255);
				}
				else if (Main.rand.Next(8) == 0 && NPC.CountNPCS(563) < num2)
				{
					num8 = NPC.NewNPC(x, y, 563, 0, 0f, 0f, 0f, 0f, 255);
				}
				else if (NPC.CountNPCS(554) + NPC.CountNPCS(557) < num)
				{
					num8 = NPC.NewNPC(x, y, 554, 0, 0f, 0f, 0f, 0f, 255);
				}
				break;
			case 4:
				if (Main.rand.Next(24) == 0 && !NPC.AnyNPCs(565))
				{
					num8 = NPC.NewNPC(x, y, 565, 0, 0f, 0f, 0f, 0f, 255);
				}
				else if (Main.rand.Next(12) == 0 && NPC.CountNPCS(571) < num6)
				{
					num8 = NPC.NewNPC(x, y, 571, 0, 0f, 0f, 0f, 0f, 255);
				}
				else if (Main.rand.Next(15) == 0 && NPC.CountNPCS(560) < num3)
				{
					num8 = NPC.NewNPC(x, y, 560, 0, 0f, 0f, 0f, 0f, 255);
				}
				else if (Main.rand.Next(7) == 0 && NPC.CountNPCS(563) < num2)
				{
					num8 = NPC.NewNPC(x, y, 563, 0, 0f, 0f, 0f, 0f, 255);
				}
				else if (Main.rand.Next(5) == 0 && NPC.CountNPCS(573) + NPC.CountNPCS(575) < num5)
				{
					if (Main.rand.Next(3) != 0)
					{
						num8 = NPC.NewNPC(x, y, 573, 0, 0f, 0f, 0f, 0f, 255);
					}
					else
					{
						num8 = NPC.NewNPC(x, y, 575, 0, 0f, 0f, 0f, 0f, 255);
					}
				}
				else if (NPC.CountNPCS(554) < num)
				{
					num8 = NPC.NewNPC(x, y, 554, 0, 0f, 0f, 0f, 0f, 255);
				}
				break;
			case 5:
				if (Main.rand.Next(20) == 0 && !NPC.AnyNPCs(577))
				{
					num8 = NPC.NewNPC(x, y, 577, 0, 0f, 0f, 0f, 0f, 255);
				}
				else if (Main.rand.Next(17) == 0 && NPC.CountNPCS(569) < num4)
				{
					num8 = NPC.NewNPC(x, y, 569, 0, 0f, 0f, 0f, 0f, 255);
				}
				else if (Main.rand.Next(8) == 0 && NPC.CountNPCS(571) < num6)
				{
					num8 = NPC.NewNPC(x, y, 571, 0, 0f, 0f, 0f, 0f, 255);
				}
				else if (Main.rand.Next(7) == 0 && NPC.CountNPCS(573) + NPC.CountNPCS(575) < num5)
				{
					if (Main.rand.Next(4) != 0)
					{
						num8 = NPC.NewNPC(x, y, 573, 0, 0f, 0f, 0f, 0f, 255);
					}
					else
					{
						num8 = NPC.NewNPC(x, y, 575, 0, 0f, 0f, 0f, 0f, 255);
					}
				}
				else if (NPC.CountNPCS(554) + NPC.CountNPCS(557) < num)
				{
					if (Main.rand.Next(3) == 0)
					{
						num8 = NPC.NewNPC(x, y, 557, 0, 0f, 0f, 0f, 0f, 255);
					}
					num9 = NPC.NewNPC(x, y, 554, 0, 0f, 0f, 0f, 0f, 255);
				}
				break;
			case 6:
				if (Main.rand.Next(20) == 0 && !NPC.AnyNPCs(577))
				{
					num8 = NPC.NewNPC(x, y, 577, 0, 0f, 0f, 0f, 0f, 255);
				}
				else if (Main.rand.Next(20) == 0 && !NPC.AnyNPCs(565))
				{
					num8 = NPC.NewNPC(x, y, 565, 0, 0f, 0f, 0f, 0f, 255);
				}
				else if (Main.rand.Next(12) == 0 && NPC.CountNPCS(571) < num6)
				{
					num8 = NPC.NewNPC(x, y, 571, 0, 0f, 0f, 0f, 0f, 255);
				}
				else if (Main.rand.Next(25) == 0 && NPC.CountNPCS(569) < num4)
				{
					num8 = NPC.NewNPC(x, y, 569, 0, 0f, 0f, 0f, 0f, 255);
				}
				else if (Main.rand.Next(7) == 0 && NPC.CountNPCS(573) + NPC.CountNPCS(575) < num5)
				{
					if (Main.rand.Next(3) != 0)
					{
						num8 = NPC.NewNPC(x, y, 573, 0, 0f, 0f, 0f, 0f, 255);
					}
					else
					{
						num8 = NPC.NewNPC(x, y, 575, 0, 0f, 0f, 0f, 0f, 255);
					}
				}
				else if (Main.rand.Next(10) == 0 && NPC.CountNPCS(560) < num3)
				{
					num8 = NPC.NewNPC(x, y, 560, 0, 0f, 0f, 0f, 0f, 255);
				}
				else if (Main.rand.Next(5) == 0 && NPC.CountNPCS(563) < num2)
				{
					num8 = NPC.NewNPC(x, y, 563, 0, 0f, 0f, 0f, 0f, 255);
				}
				else if (NPC.CountNPCS(554) + NPC.CountNPCS(557) < num)
				{
					if (Main.rand.Next(3) == 0)
					{
						num8 = NPC.NewNPC(x, y, 557, 0, 0f, 0f, 0f, 0f, 255);
					}
					num9 = NPC.NewNPC(x, y, 554, 0, 0f, 0f, 0f, 0f, 255);
				}
				break;
			case 7:
				if (Main.rand.Next(20) == 0 && NPC.CountNPCS(571) < num6)
				{
					num8 = NPC.NewNPC(x, y, 571, 0, 0f, 0f, 0f, 0f, 255);
				}
				else if (Main.rand.Next(17) == 0 && NPC.CountNPCS(569) < num4)
				{
					num8 = NPC.NewNPC(x, y, 569, 0, 0f, 0f, 0f, 0f, 255);
				}
				else if (Main.rand.Next(10) == 0 && NPC.CountNPCS(563) < num2)
				{
					num8 = NPC.NewNPC(x, y, 563, 0, 0f, 0f, 0f, 0f, 255);
				}
				else if (NPC.CountNPCS(554) + NPC.CountNPCS(557) < num)
				{
					if (Main.rand.Next(5) == 0)
					{
						num8 = NPC.NewNPC(x, y, 557, 0, 0f, 0f, 0f, 0f, 255);
					}
					num9 = NPC.NewNPC(x, y, 554, 0, 0f, 0f, 0f, 0f, 255);
				}
				break;
			default:
				num8 = NPC.NewNPC(x, y, 554, 0, 0f, 0f, 0f, 0f, 255);
				break;
			}
			if (Main.netMode == 2 && num8 < 200)
			{
				NetMessage.SendData(23, -1, -1, null, num8, 0f, 0f, 0f, 0, 0, 0);
			}
			if (Main.netMode == 2 && num9 < 200)
			{
				NetMessage.SendData(23, -1, -1, null, num9, 0f, 0f, 0f, 0, 0, 0);
			}
		}

		// Token: 0x0400413B RID: 16699
		private const int INVASION_ID = 3;

		// Token: 0x0400413C RID: 16700
		private static readonly Color INFO_NEW_WAVE_COLOR = new Color(175, 55, 255);

		// Token: 0x0400413D RID: 16701
		private static readonly Color INFO_START_INVASION_COLOR = new Color(50, 255, 130);

		// Token: 0x0400413E RID: 16702
		public static bool DownedInvasionT1 = false;

		// Token: 0x0400413F RID: 16703
		public static bool DownedInvasionT2 = false;

		// Token: 0x04004140 RID: 16704
		public static bool DownedInvasionT3 = false;

		// Token: 0x04004141 RID: 16705
		public static bool LostThisRun = false;

		// Token: 0x04004142 RID: 16706
		public static bool WonThisRun = false;

		// Token: 0x04004143 RID: 16707
		public static int LaneSpawnRate = 60;

		// Token: 0x04004144 RID: 16708
		private static bool _downedDarkMageT1 = false;

		// Token: 0x04004145 RID: 16709
		private static bool _downedOgreT2 = false;

		// Token: 0x04004146 RID: 16710
		private static bool _spawnedBetsyT3 = false;

		// Token: 0x04004147 RID: 16711
		public static bool Ongoing = false;

		// Token: 0x04004148 RID: 16712
		public static Rectangle ArenaHitbox = default(Rectangle);

		// Token: 0x04004149 RID: 16713
		private static int _arenaHitboxingCooldown = 0;

		// Token: 0x0400414A RID: 16714
		public static int OngoingDifficulty = 0;

		// Token: 0x0400414B RID: 16715
		private static List<Vector2> _deadGoblinSpots = new List<Vector2>();

		// Token: 0x0400414C RID: 16716
		private static int _crystalsDropping_lastWave = 0;

		// Token: 0x0400414D RID: 16717
		private static int _crystalsDropping_toDrop = 0;

		// Token: 0x0400414E RID: 16718
		private static int _crystalsDropping_alreadyDropped = 0;

		// Token: 0x0400414F RID: 16719
		private static int _timeLeftUntilSpawningBegins = 0;
	}
}
